package logic;

import java.io.Serializable;
import java.util.Vector;

public class Continent implements Serializable{
	
	private static final long serialVersionUID = 1L;
	private Vector<Country> territoriesContained;
	private String name;
	private boolean little;
	
	public Continent(String name){
		this.name=name;
		territoriesContained = new Vector<Country>();
	}
	
	public Continent(String name, boolean little){
		this(name);
		this.little = little;
	}
	
	
	public void addCountry(Country country){
		territoriesContained.add(country);
	}
	public String toString(){
		return name;
	}

	/**
	 * @return the territoriesContained
	 */
	public Vector<Country> getTerritoriesContained() {
		return territoriesContained;
	}
	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	public boolean isOwnedBy(Player player) {
		for(Country country: this.territoriesContained) {
			if (country.hasOwner() == false || !country.getOwner().equals(player))
				return false;
		}
		return true;
	}
	
	/**
	 * @return true iff the player owns the continent and has at least numberOfSoldiers
	 *         on each country on the continent
	 * @param player
	 * @param numberOfSoldiers
	 */
	public boolean isOwnedBy(Player player, int numberOfSoldiers) {
		for(Country country: this.territoriesContained) {
			if(!country.hasOwner()) return false;
			if(country.getSoldiers() < numberOfSoldiers) return false;
			if(!country.getOwner().equals(player)) return false;
		}
		return true;
	}
	
	public boolean equals(Object continent){
		Continent temp = (Continent)continent;
		return temp.getName().equals(this.name);
	}
	
	/**
	 * @return true iff this continent is little
	 */
	public boolean isLittle(){
		return this.little;
	}
}
